<?php
package("Query");
package("Expression");


class Query_Delete implements Query_Builder {
	/**
	 * @var Expression_Operator_Left
	 */
	private $_delete; // DELETE FROM users WHERE id = '1'
	
	/**
	 * @var Expression_Operator
	 */
	private $_where;
	
	public function __construct() {
		$factory = Expression_Operator_Factory::getSingleton();
		$this->_delete= $factory->construct("delete", array());		
		$this->_where = $factory->construct("where", array());
	}
	
	public function bindTable($table) {
		$table = new Expression_Operand_Table($table);
		$factory = Expression_Operator_Factory::getSingleton();
		$from = $factory->construct("from", array($table));
		$this->_delete->addOperand($from);
		$this->_delete->addOperand($this->_where);
	}
	
	public function bindKey(Core_Property $bound) {
		$column = new Expression_Operand($bound->column);
		$value = new Expression_Operand_Variable($bound->value);
		$factory = Expression_Operator_Factory::getSingleton();
		$equals = $factory->construct("equals", array($column, $value));
		$this->_where->addOperand($equals);
	}
	
	public function bindProperty(Core_Property $bound) {
		// do nothing with the properties in this case
	}
	
	public function toSql() {
		return $this->_delete->evaluate();
	}
}
?>